package com.jieao.backend.controller.site;

import com.jieao.biz.domain.SiteIntercept;
import com.jieao.common.annotation.Log;
import com.jieao.common.core.controller.BaseController;
import com.jieao.common.core.domain.AjaxResult;
import com.jieao.common.core.page.TableDataInfo;
import com.jieao.common.enums.BusinessType;
import com.jieao.framework.util.ShiroUtils;
import com.jieao.site.service.ISiteInterceptService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description 前端访问拦截配置
 * @Author weifanl
 * @Date2020/5/18 15:32
 **/
@Controller
@RequestMapping("/site/intercept")
public class InterceptController extends BaseController{

    private String prefix = "backend/site/intercept";

    @Autowired
    private ISiteInterceptService siteInterceptService;

    @RequiresPermissions("site:intercept:view")
    @GetMapping()
    public String intercept()
    {
        return prefix + "/intercept";
    }
    /**
     * 查询配置列表
     */
    @RequiresPermissions("site:intercept:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SiteIntercept intercept)
    {
        startPage();
        List<SiteIntercept> list = siteInterceptService.selectSiteInterceptList(intercept);
        return getDataTable(list);
    }

    /**
     * 新增配置页面
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存配置
     */
    @Log(title = "前端拦截配置", businessType = BusinessType.INSERT)
    @RequiresPermissions("site:intercept:add")
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@Validated SiteIntercept intercept)
    {
        intercept.setCreateBy(ShiroUtils.getLoginName());
        return toAjax(siteInterceptService.insertSiteIntercept(intercept));
    }

    /**
     * 修改配置页面
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        mmap.put("intercept", siteInterceptService.selectInterceptById(id));
        return prefix + "/edit";
    }

    /**
     * 修改保存拦截配置
     */
    @Log(title = "拦截配置", businessType = BusinessType.UPDATE)
    @RequiresPermissions("site:intercept:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@Validated SiteIntercept intercept)
    {
        return toAjax(siteInterceptService.updateIntercept(intercept));
    }

    @Log(title = "拦截配置", businessType = BusinessType.DELETE)
    @RequiresPermissions("site:intercept:remove")
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(siteInterceptService.deleteInterceptByIds(ids));
    }

}



